import {Injectable} from '@angular/core';
import {Observable} from "rxjs/Observable";
import {RequestUtil} from "../../../../util/request-util";
import {MsgResult} from "../../../../models/msg-result";
import {Content} from "./Content";
import {MsgAPI} from '../../msg-constants';

@Injectable()
export class RecordService {

  constructor(private requestUtil: RequestUtil,) {
  }

  /**
   * 根据id查询
   * @request :http://localhost:8080/one-admin/api/accounts/123?format=json
   * @param id:账号id；
   * @returns {Observable<MsgResult>|any}
   */
  getMsgContentById(id): Observable<MsgResult> {
    let params = "id=" + id;
    return this.requestUtil.get(MsgAPI.getMsgContentById + "?format=json&" + params);
  }

  /**
   * 修改
   *
   * @param area
   * @returns {Observable<MsgResult>|any}
   */
  dealRecord(content: Content): Observable<MsgResult> {
    let params = "id=" + content.id + "&handler=" + content.handler + "&handleStatus=" + content.handleStatus +"&handleTime="+content.handleTime;
    return this.requestUtil.put(MsgAPI.editMsgContent + "?format=json&" + params);
  }

  exportExcelData(content): any {
    let params = "siteName=" + content.siteName + "&type=" + content.type
      + "&startTime=" + content.startTime + "&endTime=" + content.endTime;
    console.log(JSON.stringify(params));
    return this.requestUtil.getFile(MsgAPI.exportExcelData , params);
  }

  sendExcelData(content): any {
    let params = "siteName=" + content.siteName + "&type=" + content.type
      + "&startTime=" + content.startTime + "&endTime=" + content.endTime;
    return this.requestUtil.get(MsgAPI.sendAlarmInformation , params);
  }

  getAlarmContentSummary(): Observable<MsgResult> {
    return this.requestUtil.get(MsgAPI.getAlarmContentSummary);
  }
}
